home *** CD-ROM | disk | FTP | other *** search
/ Aminet 34 / Aminet 34 (2000)(Schatztruhe)[!][Dec 1999].iso / Aminet / util / boot / ConsoleFix.lha / ConsoleFix / ConsoleFix.asm next >
Encoding:
Assembly Source File  |  1999-10-17  |  6.7 KB  |  244 lines

  1.         opt o+,ow-
  2. ;*************************************************
  3. ;** PatchConsole                                **
  4. ;** Patches a stupid bug in the console device  **
  5. ;*************************************************
  6.  
  7.         section main_code,code
  8.  
  9.         include inc:macros.asm
  10.         include inc:exec_lib.asm
  11.         include inc:dos_lib.asm
  12.  
  13. PatchConsole:
  14.         move.l ExecBase,a6
  15.  
  16.         sub.l a5,a5
  17.         lea DOSName(pc),a1
  18.         moveq #39,d0
  19.         jsr OpenLibrary(a6)
  20.         move.l d0,a5
  21.  
  22.         jsr Forbid(a6)
  23.  
  24.         move.l a5,d0
  25.         beq .notpatched
  26.  
  27.         lea $15e(a6),a0                 ;device list
  28.         lea ConsoleName(pc),a1
  29.         jsr FindName(a6)                ;don't try this stunt yourself
  30.         tst.l d0
  31.         beq .notpatched
  32.  
  33.         move.l d0,a0
  34.         move.w $14(a0),d1               ;get version
  35.         cmp.w #39,d1                    ;must be V39 or V40
  36.         beq.s .foundV39
  37.         cmp.w #40,d1                    ;or V40 ?
  38.         bne .notpatched
  39. .foundV39:
  40.  
  41.         moveq #5,d2                     ;RetryCount
  42. .reloop:
  43.  
  44.         lea ConsoleName(pc),a1
  45.         jsr FindTask(a6)                ;don't try this yourself
  46.         tst.l d0
  47.         beq .retry
  48.  
  49.         move.l d0,a4
  50.         move.w $e(a4),d0                ;get the state of the task
  51.         subq.w #$4,d0                   ;must be waiting
  52.         bne .retry
  53.  
  54.         move.l $36(a4),a1               ;get the stack pointer
  55.         move.l $3e(a4),a3               ;check up to this address
  56.         do
  57.          cmp.l a3,a1
  58.          bhs .retry
  59.          move.l (a1),a0                 ;read the return address
  60.          cmp.l #$f80004,a0              ;must be above this one
  61.          blo.s .next
  62.          cmp.l #$ffffff,a0              ;and below this one
  63.          bhi.s .next
  64.          move.l -4(a0),d0               ;read the instruction at this address
  65.          cmp.l #$4eaefec2,d0            ;must be Wait(a6)
  66.          bne.s .next
  67.  
  68.          move.w $3c(a0),d0              ;read first bsr.s
  69.          cmp.w #$6100,d0                ;long branch is not allowed
  70.          beq.s .next
  71.          and.w #$ff01,d0                ;mask out the jump distance
  72.          cmp.w #$6100,d0                ;must be bsr
  73.          bne.s .next
  74.  
  75.          move.w $5c(a0),d0              ;read first bsr.w
  76.          cmp.w #$6100,d0                ;must be bsr
  77.          bne.s .next
  78.  
  79.          move.w $82(a0),d0              ;read again instruction
  80.          cmp.w #$6100,d0                ;must be bsr.w again
  81.          beq.s .found                   ;if this matches, too, we got it.
  82. .next:
  83.          addq.l #2,a1                   ;next word
  84.         loop.s
  85. .found:
  86.         move.l a1,a4                    ;the return address is kept here
  87.  
  88.         lea $84(a0),a1                  ;get first extension word
  89.         move.w (a1),d0                  ;read jump distance
  90.         adda.w d0,a1                    ;the destination of the third jump
  91.         move.l a1,2+RomJump3            ;stunt! Patch in the code
  92.  
  93.         lea $5e(a0),a2
  94.         move.w (a2),d0
  95.         adda.w d0,a2
  96.         cmp.l a1,a2                     ;these two must go to the same address. Argh.
  97.         bne.s .retry
  98.         move.l a1,2+RomJump2
  99.  
  100.         lea $3c(a0),a1                  ;read first jump
  101.         move.w (a1)+,d0                 ;this is a short jump
  102.         and.w #$00ff,d0                 ;get the jump distance
  103.         bne.s .final
  104. .retry:
  105.         exg.l a5,a6
  106.         moveq #10,d1
  107.         jsr Delay(a6)                   ;wait a while
  108.         exg.l a5,a6
  109.         subq.l #1,d2
  110.         bne .reloop
  111.         bra.s .notpatched
  112.  
  113. .final:                                 ;if this is long, don't.
  114.         adda.w d0,a1                    ;calculate destination
  115.         move.l a1,2+RomJump1            ;destination
  116.  
  117.         move.l #WaitBack,(a4)           ;patch return address. Huh!
  118.                                         ;we're done now
  119.         jsr CacheClearU(a6)             ;done
  120.  
  121.         lea PatchConsole(pc),a0
  122.         clr.l -4(a0)                    ;release segment: Urghl.
  123.         moveq #0,d0                     ;Yes, I know this is ugly.
  124.         bra.s .exit
  125. .notpatched:
  126.         moveq #32,d0
  127. .exit:
  128.         jsr Permit(a6)                  ;does not alter the registers
  129.  
  130.         move.l d0,d2
  131.  
  132.         move.l a5,d0
  133.         beq.s .notclose
  134.         move.l a5,a1                    ;if open,
  135.         jsr CloseLibrary(a6)            ;close DOS again
  136.  
  137. .notclose:
  138.         move.l d2,d0
  139.         rts
  140.  
  141.         dc.b "$VER: ConsoleFix 1.1 (25.9.99) © THOR",0
  142. ConsoleName:
  143.         dc.b "console.device",0
  144. DosName:
  145.         dc.b "dos.library",0
  146.  
  147.  
  148. ;*************************************************
  149. ;** The following is the replacement            **
  150. ;** code of the console.device                  **
  151. ;*************************************************
  152.  
  153.         section patched_code,code
  154.  
  155. PatchStart:
  156.  
  157. _loop:
  158.         move.b  $152(a6),d0
  159.         move.b  d0,d1
  160.         and.b   #$1C,d1
  161.         beq.s _release
  162.         btst    #7,d0
  163.         beq.s _release
  164.         bset    #5,d0
  165.         bne.s _release
  166.         move.b  d0,$152(a6)
  167.         move.l  $125A(a6),d0
  168.         beq.s _release
  169.         lea     $1246(a6),a1
  170.         move.w  #9,$1C(a1)
  171.         clr.b   $1E(a1)
  172.         moveq   #0,d1
  173.         move.l  d1,$20(a1)
  174.         move.l  #$186A0,$24(a1)
  175.         move.l  a6,-(a7)
  176.         movea.l d0,a6
  177.         jsr     -$1E(a6)
  178.         movea.l (a7)+,a6
  179. _release:
  180.         lea     $54(a6),a0
  181.         move.l  a6,-(a7)
  182.         movea.l $30(a6),a6
  183.         jsr     -$23A(a6)
  184.         movea.l (a7)+,a6
  185.         move.l  #$F0000000,d0
  186.         move.l  a6,-(a7)
  187.         movea.l $30(a6),a6
  188.         jsr     -$13E(a6)
  189. WaitBack:
  190.         movea.l (a7)+,a6
  191.         move.l  d0,d7
  192.         lea     $54(a6),a0
  193.         move.l  a6,-(a7)
  194.         movea.l $30(a6),a6
  195.         jsr     -$2A6(a6)
  196.         movea.l (a7)+,a6
  197.         tst.l   $50(a6)
  198.         beq _loop
  199.         move.l  d7,d0
  200.         andi.l  #$C0000000,d0
  201.         beq.s _test
  202.  
  203.         move.l  d7,-(a7)
  204.         lea     $126E(a6),a0
  205.         move.l  a6,-(a7)
  206.         movea.l $30(a6),a6
  207.         jsr     -$234(a6)
  208.         movea.l (a7)+,a6
  209.         lea     $82(a6),a2             ;this is the bug
  210.         bra.s _enterloop
  211. _windowloop:
  212.  
  213. RomJump1:
  214.         jsr $55555554                   ;this is the correct address for 40.63
  215. _enterloop:
  216.         movea.l (a2),a2
  217.         tst.l   (a2)
  218.         bne.s _windowloop
  219.         lea     $126E(a6),a0
  220.         move.l  a6,-(a7)
  221.         movea.l $30(a6),a6
  222.         jsr     -$23A(a6)
  223.         movea.l (a7)+,a6
  224.         move.l  (a7)+,d7
  225. _test:
  226.         btst    #$1D,d7
  227.         beq.s _no1d
  228. RomJump2:
  229.         jsr $aaaaaaaa                   ;ditto
  230. _no1d:
  231.         btst    #$1C,d7
  232.         beq _loop
  233.         lea     $1224(a6),a0
  234.         move.l  a6,-(a7)
  235.         movea.l $30(a6),a6
  236.         jsr     -$174(a6)
  237.         movea.l (a7)+,a6
  238.         bclr    #5,$152(a6)
  239.         beq _loop
  240. RomJump3:
  241.         jsr $aaaaaaaa
  242.         beq _loop
  243.  
  244.